﻿using System;
using System.Linq;
using DataModel.Managers;

namespace UniversityPortal.Models
{
    public class Accessor
    {
        private readonly DataModel.Models.UserModel _user;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userID"></param>
        public Accessor(Guid userID)
        {
            _user = new UserManager().GetUser(userID);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="roles"></param>
        /// <returns></returns>
        public bool IsUserInRole(string roles)
        {
            string [] permitRoles = roles.Split(',','.');
            return (_user != null && _user.Roles.Any(r => permitRoles.Any(pr => pr == r.Name)));
        }
    }
}